<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body>
    <script>
      //父级构造函数
      function SuperType(name) {
        this.name = name;
      }
      //父级原型对象
      SuperType.prototype.f1 = function () {
        console.log(this.name);
      };

      //子级构造函数
      function SubType(name,age) {
        SuperType.call(this, name); //调用父级构造函数，传参
        this.age = age;
      }
      SubType.prototype.f2 = function () {
        console.log(this.name,this.age)
      }
      SubType.prototype.__proto__ = SuperType.prototype;

      let instance1 = new SubType('小白',21);
      let instance2 = new SubType('小红',22);

      instance1.f1();
      instance1.f2();

      instance2.f1();
      instance2.f2();
    </script>
  </body>
</html>
